package com.qianyu.project.mapper.provider;

import org.apache.ibatis.jdbc.SQL;
import org.springframework.util.StringUtils;

import java.util.Map;

/**
 * author wyh
 * Date 2021/2/10
 **/
public class SubSettleProvider {
    public String getSubcontracts(Map<String, Object> map){
        return new SQL(){
            {
                SELECT("*");
                FROM("sub_settle ls,project_info pi,provider_info pri,emp e,labor_subcontract ll");
                WHERE("ls.p_id=pi.id and ls.pro_id=pri.id and ls.e_id=e.id and ls.con_id=ll.i");
                if(!StringUtils.isEmpty(map.get("jsId"))){
                    WHERE("ls.sb_Id='"+map.get("jsId")+"'");
                }
                if(!StringUtils.isEmpty(map.get("jsName"))){
                    WHERE("ls.js_name like '%"+map.get("jsName")+"%'");
                }
                if(!StringUtils.isEmpty(map.get("projectName"))){
                    WHERE("pi.project_name like '%"+map.get("projectName")+"%'");
                }
                if(!StringUtils.isEmpty(map.get("providerName"))){
                    WHERE("pri.provider_name like '%"+map.get("providerName")+"%'");
                }
                if(!StringUtils.isEmpty(map.get("contractName"))){
                    WHERE("ll.contract_name like '%"+map.get("contractName")+"%'");
                }
                if(!StringUtils.isEmpty(map.get("name"))){
                    WHERE("e.name like '%"+map.get("name")+"%'");
                }
                if(!StringUtils.isEmpty(map.get("startDate")) && !StringUtils.isEmpty(map.get("endDate"))){
                    WHERE("ls.create_date>='"+map.get("startDate")+"' and ls.create_date<='"+map.get("endDate")+"'");
                }
                if(!StringUtils.isEmpty(map.get("approveStatus"))){
                    WHERE("ls.approve_status = '"+map.get("approveStatus")+"'");
                }
            }
        }.toString();
    }
}
